-
Notifications
You must be signed in to change notification settings - Fork 660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure NoJump handles jumps that occur on the second frame in NPT trajectories #4258
Ensure NoJump handles jumps that occur on the second frame in NPT trajectories #4258
Conversation
Linter Bot Results:Hi @p-j-smith! Thanks for making this PR. We linted your code and found the following: Some issues were found with the formatting of your code.
Please have a look at the Please note: The |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## develop #4258 +/- ##
==========================================
Coverage 93.40% 93.40%
==========================================
Files 170 184 +14
Lines 22246 23358 +1112
Branches 4071 4071
==========================================
+ Hits 20779 21818 +1039
- Misses 951 1024 +73
Partials 516 516
☔ View full report in Codecov by Sentry. |
I've removed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny little nitpicks, but other than that looking great. Don't forget CHANGELOG ;)
thanks for the speedy review @hmacdope! And sorry for mixing a fix and a feature in the same pr - I probably should have added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One initial blocking request - I'll follow up with smaller review things.
@@ -92,3 +93,74 @@ def __init__(self, | |||
def _transform(self, ts): | |||
ts.dimensions = self.dimensions | |||
return ts | |||
|
|||
|
|||
class set_variable_dimensions(TransformationBase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just move this new functionality as a new option of the existing set_dimension
? The order of how things are done is very similar and it would be a much better user experience to not have to deal with (choose between) a lot of classes that do very similar things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep I think that would make sense
dim = [ | ||
[2, 2, 2, 90, 90, 90], | ||
[4, 4, 4, 90, 90, 90], | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use a numpy array in the example if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the "small changes" review
try: | ||
ts.dimensions = self.dimensions[ts.frame] | ||
except IndexError as e: | ||
raise NoDataError(f"Dimensions array has no data for frame {ts.frame}") from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per #3901, NoDataError
is really only meant to exist within the realm of TopologyAttr
. A ValueError
probably should be used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah okay, that's good to know
ts = variable_boxdimensions_universe.trajectory.ts | ||
with pytest.raises(ValueError, match='valid box dimension shape'): | ||
set_variable_dimensions(dim_vector_shapes)(ts) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… on the second frame Previosuly, jumps wouldn't be unwrapped until the third frame due to the way the class was initialised. To fix the issue, the NoJump transformation now requires an 'ag' argument, which is used to determine the box size at the first frame
…nd and third frames Also update other tests to pass the 'ag' argument to the transformation
For creating NPT trajectories
…imensions are missing for a frame
…values at all frames when iterating over multiple times
over the trajectory multiple times
…ted unwrapping Also don't pass 'ag' argument to NoJump in tests
Co-authored-by: Hugo MacDermott-Opeskin <[email protected]>
Co-authored-by: Hugo MacDermott-Opeskin <[email protected]>
Co-authored-by: Irfan Alibay <[email protected]>
It can be set to any number, just not 'A'.
…ndled correctly by NoJump
5cbba9c
to
2a2d100
Compare
Thanks for the reviews @richardjgowers and @IAlibay ! I think I've addressed all your comments, and I've just rebased on to the latest develop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple more small things, otherwise lgtm
'[a, b, c, alpha, beta, gamma]') | ||
raise ValueError(errmsg) | ||
|
||
def _transform(self, ts): | ||
ts.dimensions = self.dimensions | ||
try: | ||
ts.dimensions = self.dimensions[0] if self.dimensions.shape[0] == 1 else self.dimensions[ts.frame] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is both a long line and also a bit hard to read (at least to me), splitting this over a few lines probably would be worth it?
try: | ||
ts.dimensions = self.dimensions[0] if self.dimensions.shape[0] == 1 else self.dimensions[ts.frame] | ||
except IndexError as e: | ||
raise ValueError(f"Dimensions array has no data for frame {ts.frame}") from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise ValueError(f"Dimensions array has no data for frame {ts.frame}") from e | |
errmsg = f"Dimensions array has no data for frame {ts.frame}" | |
raise ValueError(errmsg) from e |
I know it's annoying but pep8 - note we don't care about the black
linter stuff, but the flake8 errors from here probably should be addressed: https://github.com/MDAnalysis/mdanalysis/actions/runs/5997923144/job/16265248319
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah sorry I forgot to run flake8 locally, fixed now! Perhaps adding a pre-commit config for people to optionally use would be useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre-commit config for people to optionally use would be useful?
It's.. complicated, I'll leave it as that for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha! okay :)
I just realised that with the changes in this pr there are now some parts of |
@hmacdope could you be the one looking after this PR, chasing reviews if necessary, and merging, i.e., assign it to you? |
Co-authored-by: Irfan Alibay <[email protected]>
Yep, ill re-review ASAP. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me @p-j-smith. Thank you so much for the detailed bug report, timely fix and detailed testing! Its really appreciated.
Thanks for the speedy reviews everyone! |
Thank you for the contribution, Paul. Really good work!Am 9/3/23 um 09:39 schrieb Paul Smith ***@***.***>:
Thanks for the speedy reviews everyone!
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
Fixes #4257
Changes made in this Pull Request:
ensure jumps across periodic boundaries that occur at the second frame are accounted for by
mda.transformations.NoJump
added two tests:
test_nojump_2nd_frame
.- tests that jumps that occur on the second frame are handled correctlytest_nojump_3rd_frame
.- tests that jumps that occur on the third frame are handled correctlythe
test_nojump_3rd_frame
test isn't necessary and can probably be removed. However, I've included it here to illustrate the the fix in this pr is necessary. Before this pr,test_nojump_3rd_frame
would pass buttest_nojump_2nd_frame
would fail, and the only difference between the trajectories is the frame at which the jump across a boundary occursthe fix requires that we know the atom positions and box size at the first frame of the trajectory, and so I've added an
ag
argument that takes an AtomGroup to be unwrapped. This however would be a breaking change to the api. Perhaps a better way would be to add an if-statement tomda.transformations.NoJump._transform
that checks if we're on the first frame of the trajectory, and if so then sets the appropriate values forNoJump.prev
,NoJump.old_frame
, andNoJump.older_frame
?updated all other tests for nojump to use the required
ag
argumentNote, I've temporarily put the test datasets in the testsuite itself so the tests can run before the datasets are added toMDAnalysisData
Edit: I was running into some issues with CI failing because the test datafiles I added weren't present in
MDAnalysisData
. So I've added a tranformationmda.transformations.boxdimensions.set_variable_dimensions
to set different box dimensions at each frame (so we can create an NPT trajectory to go withmda.Universe.empty
).PR Checklist
Developers certificate of origin